/** 尝试使用Timer来做连发,保证中止时连发完整结束
  
*/

class TimerAutoFire {

  __New() {
      this.interval := 30
      this.key := "w"
      this.timer := ObjBindMethod(this, "_autoFire")
      this.timerOn := False ;timer是否开启
    }

  _autoFire(){
    local downStr := "{" . this.key . " down}"
    local upStr := "{" . this.key . " up}"
    send(downStr)
    sleep(this.interval)
    send(upStr)
  }

  _start(key){
    if (!this.timerOn){
      SetTimer this.timer, this.interval
      this.timerOn := True
    }
  }
  
  _stop(key){
    if (this.timerOn){
      SetTimer this.timer, 0
      this.timerOn := False
    }
  }

  main(){
    Hotkey("s", ObjBindMethod(this, "_start"))
    Hotkey("a", ObjBindMethod(this, "_stop"))
  }

}

TimerAutoFire().main()